package logic

import (
	"context"
	"user-reg8/model"

	"user-reg8/userrpc/internal/svc"
	"user-reg8/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *userrpc.HouseListRequest) (*userrpc.HouseListResponse, error) {
	// todo: add your logic here and delete this line

	var houses []model.House

	model.DB.Debug().Find(&houses)

	var houseList []*userrpc.HouseList
	for _, house := range houses {

		list := userrpc.HouseList{
			UserId:  int64(house.UserId),
			Title:   house.Title,
			Address: house.Address,
			Price:   float32(house.Price),
		}
		houseList = append(houseList, &list)

	}
	return &userrpc.HouseListResponse{
		List: houseList,
	}, nil
}
